<?php require_once('../src/session_start.inc.php'); ?>
<?php
require_once('../src/functions.php');
require_once('../lib/myCurrencyConverter.php');
require_once('../src/Exchange.class.php');
$exchange = new Exchange();

if ( isset($_REQUEST['from']) && isset($_REQUEST['to']) )
{
	$currencyFrom = $_REQUEST['from'];
	$currencyTo = $_REQUEST['to'];
}
else
{
	header('Location: change.php?nodata');
}

if ( isset($_POST['rate']) && $_POST['rate']!="" )
{
	$exchange->currency_from = $currencyFrom;
	$exchange->currency_to = $currencyTo;
	$exchange->rate = $_POST['rate'];
	$exchange->save();

	header('Location: change.php'); exit();
}
?>
<?php require_once('admin_header.php'); ?>

<h2>Taux de change</h2>

<p class="biginfo">
	Votre taux de change enregistré est de:
	<b><?php echo Exchange::getRate($currencyFrom, $currencyTo, true, true) ?></b>
</p>

<p class="message">
	<span class="biginfo">Le taux de change actuel a la bourse est de:<br/>
	<b><?php echo $rate = myCurrencyConverter($currencyFrom, $currencyTo) ?></b></span>
</p>

<form class="currency" action="change_update.php" method="post">
	<p>
		<input type="hidden" name="from" value="<?php echo $currencyFrom ?>" />
		<input type="hidden" name="to" value="<?php echo $currencyTo ?>" />
		<input type="hidden" name="rate" value="<?php echo $rate ?>" />
	</p>
	<p><input type="submit" class="submit" name="submit" value="Enregistrer cette valeur !" /></p>
</form>


<?php require_once('admin_footer.php'); ?>